<template>
	<div>
		<div>
		   <div>
		        <el-button type="primary" @click="addBtn" size="mini">添加</el-button>
		    </div>
		</div>
		<br>
		<el-table  :data="list"
			 border  
			 style="width: 100%"
			>
			<el-table-column   align="center"    prop="goods_code"    label="金属类型编号"></el-table-column>
			<el-table-column   align="center"    prop="goods_type_name"    label="金属类型名称"></el-table-column>
			 <el-table-column  label="状态"   align="center">
			      <template slot-scope="scope">
			         <div>
						<el-tag v-if="scope.row.status==0" size="small" effect="dark" type="danger">禁用</el-tag>
						<el-tag v-if="scope.row.status==1" size="small" effect="dark">启用</el-tag>
			 		</div>
			      </template>
			  </el-table-column>
			  <el-table-column  label="排序(数字大的在前边)"   align="center">
			       <template slot-scope="scope">
			          <div>
			  			<el-input v-model="scope.row.sort" 
			  				@change="changeSort(scope.row)"
			  				size="mini"></el-input>
			  		</div>
			       </template>
			   </el-table-column>
			  <el-table-column   align="center"    prop="float_re_price"   label="回购浮动价格"></el-table-column>
			   <el-table-column   align="center"    prop="float_sael_price"   label="销售浮动价格"></el-table-column>
			   <el-table-column   align="center"    prop="code"   label="助记码"></el-table-column>
			<!-- <el-table-column   align="center"    prop="max_price"   label="最大金额"></el-table-column>
			<el-table-column   align="center"    prop="min_price"   label="最小金额"></el-table-column> -->
			<el-table-column   align="center"    prop="use_dep"   label="定价押金"></el-table-column>
			<el-table-column   align="center"    prop="add_time"    label="添加时间"></el-table-column>
			<el-table-column   align="center"    prop="update_time"    label="修改时间"></el-table-column>
			
		   <el-table-column  label="操作"   align="center">
		        <template slot-scope="scope">
		            <span style="margin-right: 10px;" class="button_text" @click="editRow(scope.row)">编辑</span>
		            <span class="button_text" @click="delRow(scope.row.id)">删除</span>
		        </template>
		    </el-table-column>
		</el-table>
		<el-dialog
		        :title="addTitle"
				:close-on-click-modal="false"
		        :visible.sync="formShow"
		        width="700px"
		>
		  <div>
			  <el-form ref="form" :model="form" label-width="100px">
				  <el-form-item label="金属类型编号">
				      <el-input v-model="form.goods_code" size="small"></el-input>
				  </el-form-item>
				  <el-form-item label="金属类型名称">
				      <el-input v-model="form.goods_type_name" size="small"></el-input>
				  </el-form-item>
				  <el-form-item label="回购浮动价格">
				      <el-input type="number" v-model="form.float_re_price" size="small"></el-input>
				  </el-form-item>
				  <el-form-item label="销售浮动价格">
				      <el-input type="number" v-model="form.float_sael_price" size="small"></el-input>
				  </el-form-item>
				  <el-form-item label="排序">
				      <el-input type="number" v-model="form.sort" size="small"></el-input>
				  </el-form-item>
				  <el-form-item label="助记码">
				      <el-input  v-model="form.code" size="small"></el-input>
				  </el-form-item>
				  <!-- <el-form-item label="最大金额">
				      <el-input type="number" v-model="form.max_price" size="small"></el-input>
				  </el-form-item>
				  <el-form-item label="最小金额">
				      <el-input type="number" v-model="form.min_price" size="small"></el-input>
				  </el-form-item> -->
				  <el-form-item label="定价押金">
				      <el-input type="number" v-model="form.use_dep" 
						placeholder="定价1克需要多少押金"
						size="small"></el-input>
				  </el-form-item>
				  <el-form-item label="状态">
				      <el-radio-group v-model="form.status">
				        <el-radio label="0">禁用</el-radio>
				        <el-radio label="1">启用</el-radio>
				      </el-radio-group>
				    </el-form-item>
				  <el-form-item >
				      <el-button type="primary" @click="confirm" size="small">确定</el-button>
				  </el-form-item>
			  </el-form>
		  </div>
		</el-dialog>
	</div>
</template>

<script>

	export default {
		data(){
			return {
				title:"",
				page:1,
				pageSize:10,
				form:{
					id:null,
					goods_code:'',
					goods_type_name:'',
					re_price:"",
					sael_price:'',
					float_re_price:"",
					float_sael_price:'',
					max_price:"",
					min_price:'',
					status:'1',
					use_dep:"",
					sort:1,
					code:''
				},
				addTitle:'新增',
			}
		},
		components:{
			
		},
		mounted() {
			this.lodeList()
		},
		methods:{
			changeSort(row){
				for(let i in this.form){
					this.form[i] = row[i]
				}
				this.confirm()
			},
			editRow(row){
				this.addTitle = '编辑'
				for(let i in this.form){
					this.form[i] = row[i]
				}
				this.formShow = true
			},
			delRow(id){
				this.$confirm('确定删除', '提示', {
				          confirmButtonText: '确定',
				          cancelButtonText: '取消',
				          type: 'warning'
				        }).then(() => {
				          this.$post('/homeSet/delGoldPrice',{ids:[id]},res=>{
							  this.lodeList()
						  })
				        })
			},
			clearSearch(){
				this.title = ''
				this.search()
			},
			confirm(){
				this.$post('/homeSet/addGoldPrice',this.form,res=>{
					if(res.data.code==200){
						this.$message.success('操作成功')
						this.formShow = false
						this.lodeList()
					}
				})
			},
			addBtn(){
				this.addTitle = '新增'
				this.form={
					id:null,
					goods_code:'',
					goods_type_name:'',
					re_price:"",
					sael_price:'',
					float_re_price:"",
					float_sael_price:'',
					max_price:"",
					min_price:'',
					status:'1',
					use_dep:'',
					sort:1,
					code:''
				}
				this.formShow = true
			},
			lodeList(){
				let params = {
					
				}
				this.$post('/homeSet/getGoldPriceList',params,res=>{
					this.list = res.data.data
				})
			},
		}
	}
</script>

<style>
</style>